#!/usr/bin/env python3
# encoding: utf-8
"""
@author: kevin
@contact: evil365@gmail.com
@project : flask
@file: forms.py
@time: 2020/8/5 11:19
@license: (C) Copyright 2019-2025, Corporation Limited.
@desc:
"""
from wtforms import DateTimeField, PasswordField, FieldList, IntegerField, StringField
from wtforms.validators import DataRequired, Regexp, EqualTo, length, Optional, NumberRange


from lin.forms import Form


class ProductSearchForm(Form):
    q = StringField(validators=[DataRequired(message='必须传入搜索关键字')])  # 前端的请求参数中必须携带`q`


class CreateOrUpdateProductForm(Form):
    RId = IntegerField(validators=[DataRequired(message='必须传入RID值')])
    name = StringField(validators=[DataRequired(message='必须传入名称')])
    status = StringField(validators=[DataRequired(message='产品状态不能为空')])
    mandatorId = IntegerField(validators=[DataRequired(message='请输入正确的融资方')])
    bookrunnerId = IntegerField(validators=[DataRequired(message='请输入正确的承销商信息')])
    assetType = StringField(validators=[DataRequired(message='账户名称不能为空')])


class CreateOrUpdateMandatorForm(Form):
    name = StringField(validators=[DataRequired(message='输入正确的融资方名称')])
    credit = StringField(validators=[DataRequired(message='授信额度不能为空，未授信则为0')])
    status = StringField(validators=[DataRequired(message='当前状态不能为空')])
    remain = StringField(validators=[DataRequired(message='剩余募集额度不能为空，物剩余额度则为0')])
    used = StringField(validators=[DataRequired(message='已募集额度不能为空，未募集则为0')])
    remark = StringField(validators=[Optional()])


class PosionSearchForm(Form):
    q = StringField(validators=[DataRequired(message='必须传入搜索关键字')])  # 前端的请求参数中必须携带`q`


class CreateOrUpdatePosionForm(Form):
    userId = IntegerField(validators=[DataRequired(message='用户Sn不能为空'),
                                      NumberRange(message='用户Sn必须大于0')])
    productId = IntegerField(validators=[DataRequired(message='产品Sn不能为空'),
                                      NumberRange(message='产品Sn必须大于0')])
    rateSequence = StringField(validators=[DataRequired(message='利率序列不能为空'),
                               Regexp(r'[0-9]+[0-9-%\\]', message='输入正确的序列对')])
    quantity = IntegerField(validators=[DataRequired(message='请输入产品仓位数量'),
                                        Regexp(r'^[0-9]', message='数量只能是数值')])
    parentRateSequence = StringField(validators=[Optional()])
    assetType = StringField(validators=[Optional()])


class CreateOrUpdateProductRepayForm(Form):
    productId = IntegerField(validators=[DataRequired(message='产品Sn不能为空'),
                                      NumberRange(message='产品Sn必须大于0')])
    valueStartDate = DateTimeField(validators=[DataRequired(message='产品起息日不能为空')])
    ValueEndDate = DateTimeField(validators=[DataRequired(message='产品止息日不能为空')])
    settmentDate = DateTimeField(validators=[DataRequired(message='请输入产品计息本金')])
    duretion = IntegerField(validators=[DataRequired(message='请输入产品还款本金'),
                                        Regexp(r'^[0-9]', message='还款本金只能是数值')])
    type = StringField(validators=[Optional()])
